package com.hxl.linuxfilemanager.global;

import com.hxl.linuxfilemanager.entity.ErrorConstant;
import com.hxl.linuxfilemanager.entity.MessageConstant;
import com.hxl.linuxfilemanager.entity.R;
import com.hxl.linuxfilemanager.util.ResponseUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.HashMap;
import java.util.Map;

@RestControllerAdvice
public class ErrorController {
    @ResponseBody
    @ExceptionHandler(value = Exception.class)
    public R errorHandler(Exception ex) {
        String msg=ex.getMessage();
        if (msg==null){msg= MessageConstant.ERROR;
        }
        return ResponseUtils.error(ErrorConstant.ERROR,msg);
    }
}
